// mircoApp/shop_base/asset/home/index.js
let app = getApp();
const skinBehavior = require('../../../../utils/themeSkin/skinBehavior');
Page({
  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    info: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init();
  },

  init() {
    if (!this.options.api) {
      return app.tips("缺少必要参数");
    }
    this.data.info = {};
    this.getData();
  },
  async getData() {
    let _parame = this.options.extparams ? JSON.parse(this.options.extparams) : {};

    let urlStr = app.getNetAddresss(this.options.api);
    let response = await app._postNetWork({
      url: urlStr,
      data: _parame
    });
    let { result, msg, data } = response.data;
    if (result == 0) {
      return app.tips(msg);
    }

    // 模板数据
    let { page_title, ...other } = data;
    this.setData({
      info: other || {}
    });
    wx.setNavigationBarTitle({
      title: page_title
    })
  },
  toUrl(e) {
    let _data = e.currentTarget.dataset || {};
    this.wxRouterLink(_data);
  },
  wxRouterLink(_data) {
    let _Param = "";
    const {
      url,
      ...other
    } = _data;
    let otherParam = other.query;
    Object.keys(otherParam).forEach(function (key) {
      if (otherParam[key] !== "") _Param += key + "=" + otherParam[key] + "&";
    });
    
    if (url === "") return;
      wx.navigateTo({
        url: url + "?" + _Param.slice(0, -1),
        fail: ()=> {
          wx.reLaunch({
            url: url + "?" + _Param.slice(0, -1)
          });
        }
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})